package com.example.config.security.authentication;

import com.example.util.Md5;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * 自定义Secuity加密编码类
 *
 * @author wsl
 */
@Service("passwordEncoder")
public class PasswordEncoderImpl implements PasswordEncoder {

    @Override
    public String encode(CharSequence rawPassword) {
        return Md5.encrypt(rawPassword.toString());
    }

    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        return Objects.equals(Md5.encrypt(rawPassword.toString()), encodedPassword);
    }
}
